﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace AdminizzaUIDesktop.UIComponents
{
    public partial class AdminizzaTextbox : UserControl
    {
        public string LabelText
        {
            get { return this.labelFor.Text; }
            set { this.labelFor.Text = value; }
        }

        public void setHiddenText(bool isHidden)
        {
            if (isHidden) this.textBox.PasswordChar = '*';
        }

        public int MaxLength
        {
            get { return this.textBox.MaxLength; }
            set { this.textBox.MaxLength = value; }
        }

        public string TextValue
        {
            get { return this.textBox.Text; }
            set { this.textBox.Text = value; }
        }

        public AdminizzaTextbox()
        {
            InitializeComponent();
            this.SetAdminizzaStyle();
            this.SetBehaivor();
        }
        public AdminizzaTextbox(string fieldName)
        {
            InitializeComponent();
            this.labelFor.Text = fieldName;
            this.SetAdminizzaStyle();
            this.SetBehaivor();
        }
        private void SetAdminizzaStyle()
        {
            this.textBox.Font = new System.Drawing.Font("Arial", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.labelFor.Font = new System.Drawing.Font("Arial", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 

        }

        public void RemarkError()
        {
            this.BackColor = System.Drawing.Color.LightCoral;
            this.ForeColor = System.Drawing.Color.White;
        }

        public void DefaultState()
        {
            this.BackColor = System.Drawing.Color.White;
            this.ForeColor = System.Drawing.Color.Black;
        }

        private void SetBehaivor()
        {
            this.textBox.Enter += new EventHandler(textBox_Enter);
            this.textBox.Leave += new EventHandler(textBox_Leave);
        }


        void textBox_Leave(object sender, EventArgs e)
        {
            this.textBox.BackColor = System.Drawing.Color.White;
        }

        void textBox_Enter(object sender, EventArgs e)
        {
            this.textBox.BackColor = System.Drawing.SystemColors.Info;
        }
    }
}
